/*  chat_cset.c
 *
 *  copyright (c) 2000-2003 SeaD
 *  see GPL for copying info
 *
 */

#ifdef  CHARSET

#include "echat.h"

void cset_inout(void) {
    char src[] =        /* russian cyrillic koi8-r codepage */
        { 193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
          225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241 };
    char dst[] =        /* russian insane 1251 codepage */
        { 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
          192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223 };
    register int n, m;

    for (n = 0; n < MSG_SIZE; n++)
        if (packet[n] < 0)
            for (m = 0; m < sizeof(src); m++)
                if (packet[n] == src[m]) { packet[n] = dst[m]; break; }
}

void cset_outin(void) {
    char dst[] =        /* russian cyrillic koi8-r codepage */
        { 193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
          225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241 };
    char src[] =        /* russian insane 1251 codepage */
        { 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255,
          192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223 };
    register int n, m;

    for (n = 0; n < MSG_SIZE; n++)
        if (packet[n] < 0)
            for (m = 0; m < sizeof(src); m++)
                if (packet[n] == src[m]) { packet[n] = dst[m]; break; }
}

void cset_string(void) {
    char kbd[] =        /* keyboard layout */
        { 'f',',','d','u','l','t',';','p','b','q','r','k','v','y','j','g','h','c','n','e','a','[','w','x','i','o',223,'s','m','\'','.','z',
          'F','<','D','U','L','T',':','P','B','Q','R','K','V','Y','J','G','H','C','N','E','A','{','W','X','I','O',255,'S','M','\"','>','Z' };
    char chr[] =        /* russian cyrillic koi8-r codepage */
        { 193,194,215,199,196,197,214,218,201,202,203,204,205,206,207,208,210,211,212,213,198,200,195,222,219,221,223,217,216,220,192,209,
          225,226,247,231,228,229,246,250,233,234,235,236,237,238,239,240,242,243,244,245,230,232,227,254,251,253,255,249,248,252,224,241 };
    register int n, m;

    for (n = 0; n < STR_SIZE; n++)
        for (m = 0; m < sizeof(kbd); m++) {
            if (buf[n] == kbd[m]) { buf[n] = chr[m]; break; }
            if (buf[n] == chr[m]) { buf[n] = kbd[m]; break; }
        }
}

#endif  /* CHARSET */
